import datetime
from logging import log
from fastapi import APIRouter,Request,Form,status
from src.controller.base.data_type import UserData
# from src.models.users import Users
from src.utils.respone import success,fail
from src.utils.token import createToken,vertify_is_login
from fastapi import HTTPException
from src.core.life import REDIS
from pydantic import BaseModel,Field, field_validator,validator
import re
from fastapi.responses import JSONResponse
from src.utils import respone
users_router = APIRouter()


async def route_name(request: Request, userData: UserData):
     
    # res = await Users.filter(account=userData.account).first()
    for k in request:
        print(k)
    baseRedis = request["redis"]["base"]
    await baseRedis.set("long.tests.authww", '踢啊n' )
    redisstr = await baseRedis.get("long.tests.authww")
    
    print(redisstr.decode('utf8'))
    res=None
    if(res == None):
        return fail(msg="该用户不存在")
    
    if(res.password != userData.password):
        return fail(msg="密码错误")
    
    token = createToken({"userId": res.userId, "account": res.account})
    
    # await REDIS["base"].hset("long.tests.auth", res.userId, token)
    print(vertify_is_login("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImFjY291bnQiOiJhZG1pbiIsImV4cCI6MTcyNTE4NDgxOX0.Aa_Hb_pGDpCVrZdJrDzkBJYJMmAYBDuzymuliHN4_bQ"))
  
    return success(data=token)